package cn.harvest.storage.bo.manager;

import java.util.List;

import cn.harvest.storage.dao.DAO;
import cn.harvest.storage.po.MerchandiseUnit;

public class MerchandiseUnitService {

	private DAO dao = DAO.getDAO();

	private MerchandiseUnitService() {

	}

	public static MerchandiseUnitService getService() {

		MerchandiseUnitService service = new MerchandiseUnitService();
		return service;
	}

	public boolean create(MerchandiseUnit merchandiseUnit) {

		return dao.create(merchandiseUnit);
	}
	
	public boolean update(MerchandiseUnit merchandiseUnit) {
		
		return dao.update(merchandiseUnit);
	}

	public List selectMerchandiseUnit() {

		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT mu.merchandise_unit_id, mu.merchandise_unit_name"); 
		sql.append(" FROM merchandise_unit mu");
		sql.append(" WHERE 1=1");
		sql.append(" ORDER BY mu.merchandise_unit_id;");

		System.out.println("### - MerchandiseUnitService -> selectMerchandiseUnit -> #SQL \r\n	 " + sql);
		
		return dao.selectBySQL(sql.toString());
	}
	
	public MerchandiseUnit selectByHQL(String merchandiseTypeId) {
		StringBuffer hql = new StringBuffer();
		hql.append(" FROM MerchandiseUnit mt WHERE mt.merchandiseTypeId = " + merchandiseTypeId);
		
		System.out.println("### - MerchandiseUnitService -> selectByHQL -> #HQL \r\n	 " + hql);
		
		MerchandiseUnit merchandiseUnit = (MerchandiseUnit) dao.selectByHQL(hql.toString()).get(0);
		return merchandiseUnit;
	}
	
	public static void main(String[] args) {

	}
}
